-- tests scene
local layer = nil
local _menuCallback = nil

IndexSkillTag = 100

Status_Unlock   = 0x01 --可以解锁
Status_Lock = 0x02 --不可解锁
Status_Normal   = 0x03 --已经解锁
    
local function GetSkilllvID(skid, lv)
    return skid*IndexSkillTag+lv
end
    

--------------------- 类
SkillItemClass = {}
--这句是重定义元表的索引，必须要有，
SkillItemClass.__index = SkillItemClass
--模拟构造体，一般名称为new()
function SkillItemClass:new(skid)
    local self = {}   
    setmetatable(self, SkillItemClass)   --必须要有
    
    self.id = skid
    
    
    local levelImg = "level_0%d.png"
    local skillImg = "skill_0%d.png"
    --if self._status == Status_Lock then
    --    levelImg = "levelUn_0%d.png"
    --    skillImg = "skillUn_0%d.png"
    --else
    --end
    
    -- 技能图标
    
    local skindex = SkillTable_Infos[self.id][PModel]
    self.sp_skill = GFunc_CreateButtonP(string.format(skillImg, skindex+1), function()
        _menuCallback(self)
    end)
    
    --_mainMenu:addChild(self.sp_skill, 0, self.id)
    
    -- 解锁背景
    self.sp_unlockbg = CCSprite:createWithSpriteFrameName("SkillBtnBg_01.png")
    self.sp_unlockbg:setVisible(false)
    
    -- 当前等级
    local mylevel = GetSkill(self.id) + 1
    
    self.sp_level = CCSprite:createWithSpriteFrameName(string.format(levelImg, 1))
    
    -- 价格背景
    self.priceBg = CCSprite:createWithSpriteFrameName("levelBg.png")
    -- 价格 SkillTable_Infos[self.id][PLevel][mylevel][PCount]
    self.lbprice = CCLabelTTF:create(0, "Arial", FontSizeMin)
    
    self:update()
    
    return self  
end
function SkillItemClass:getPosition()
end
function SkillItemClass:setPosition(x,y)
    if self.priceBg then
        self.priceBg:setPosition(gdccp(x,y - 30))
    end
    if self.lbprice then
        self.lbprice:setPosition(gdccp(x, y - 30))
    end
    
    if self.sp_level then
        self.sp_level:setPosition(gdccp(x+ 15,y + 30))
    end
    if self.sp_skill then
        self.sp_skill:setPosition(gdccp(x-2,y))
    end
    
    if self.sp_unlockbg then
        self.sp_unlockbg:setPosition(gdccp(x,y))
    end
    
    self._x, self._y = x,y
end

function SkillItemClass:addToLayer(layer, menu)
    menu:addChild(self.sp_skill)
    layer:addChild(self.sp_unlockbg,2)
    layer:addChild(self.sp_level,4)
    layer:addChild(self.priceBg,4)
    layer:addChild(self.lbprice,4)
end

function SkillItemClass:update()
    -- 更新
    local mylevel = GetSkill(self.id) + 1
    
    --满级
    if mylevel > 3 then
        -- 解锁背景
        self.sp_unlockbg:setVisible(true)
        self.sp_level:setVisible(false)
    
        -- 价格背景
        self.priceBg:setVisible(false)
        -- 价格
        self.lbprice:setVisible(false)
    else
        -- 更新等级数
        self.sp_level:setDisplayFrame(CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName(string.format("level_0%d.png", mylevel)))
        -- 更新价格
        self.lbprice:setString(SkillTable_Infos[self.id][PLevel][mylevel][PCount])
        
        self.sp_unlockbg:setVisible(false)
        self.sp_level:setVisible(true)
        self.priceBg:setVisible(true)
        -- 价格
        self.lbprice:setVisible(true)
    end
end


local function initWithLayer(stage)
    local _tableRole = {}
    local _tableSkillIcon = {}
    -------- ui
    -- 背景
    local _bgSpr = nil
    _bgSpr = CCSprite:createWithSpriteFrameName(s_Space_bg)
    _bgSpr:setPosition(gdccp(DWinSizeWidth/2, DWinSizeHeight/2))
    layer:addChild(_bgSpr)
    _bgSpr = CCSprite:createWithSpriteFrameName("UIRole.png")
    _bgSpr:setPosition(gdccp(DWinSizeWidth/2, DWinSizeHeight/2+50))
    layer:addChild(_bgSpr)
    --_bgSpr = CCSprite:createWithSpriteFrameName(s_Space_bgHead)
    --_bgSpr:setPosition(DWinSizeWidth/2, 960-32)
    --layer:addChild(_bgSpr, 9)
    
    local _lblSoul = GameNumbers:new(vNumberScore, NumberAlginment_Left)
    _lblSoul:addLayer(layer)
    _lblSoul:setNumber(GetSoulPower())
    _lblSoul:setPosition(gdccp(DWinSizeWidth/2-100, DWinSizeHeight-45))
    
    
    
    --- 更新角色数值显示
    local function _updateProperty()
        for k,rid in pairs({Role_Soldier, Role_Archer, Role_Master}) do
            local proobj = GetRoleProperty(rid)
            _tableRole[rid].lhp:setNumber(proobj.hp)
            _tableRole[rid].latk:setNumber(proobj.atk)
            _tableRole[rid].ldef:setNumber(proobj.def)
        end
    end
    
    -- 按钮回调函数
    _menuCallback = function (cskill)
        local mylevel = GetSkill(cskill.id)
        if mylevel >= 3 then
            -- 最高等级
            Play_Effect(sme_ClickError)
            return
        end
        
        -- 是否有足够动力值
        
        ---- 直接升级
        -- 是否有足够的魂力值
        local _jiage = SkillTable_Infos[cskill.id][PLevel][mylevel+1][PCount]
        if GetSoulPower() >= _jiage then
            -- 升级
            UpSkill(cskill.id, mylevel+1)
            
            -- 更新按钮
            cskill:update()
            --减少魂力值
            AddSoulPower(-_jiage)
            _lblSoul:setNumber(GetSoulPower())
            
            --音效
            Play_Effect(sme_Achieve)
            -- 更新属性
            _updateProperty()
        else
            -- 魂力值不足
            --CCDialogClose("魂力值不足!")
            Play_Effect(sme_ClickError)
        end
    end
    
    -- 不同的职业用不同的页面切换
    local _layerRole = CCLayer:create()
    layer:addChild(_layerRole)
    local _menu = CCMenu:create()
    _menu:setPosition(gdccp(0,0))
    _layerRole:addChild(_menu,3)
    
    
    -- 显示模型
    require "lua/ui_fight"
    -- 战场layer
    local _tableRoles = {}
    
--    createRolePanel(Role_Soldier)
--    createRolePanel(Role_Archer)
--    createRolePanel(Role_Master)

    local function createRolePanel(role)
        local _rinfo = Datas_Role[role]
        local hx,hy = 0,0
        local ax,ay = 0,0
        local dx,dy = 0,0
        local weaponX, weaponY = 0,0
        local armorX, armorY = 0,0
        local skX, skY = 0,0
        
        if role == Role_Soldier then
            ax = 275
            ay = 830
            hx = 410
            hy = 830
            dx = 275
            dy = 785
            weaponX = 500
            weaponY = 815
            armorX = 590
            armorY = 815
            skX = 350
            skY = 700
        elseif role == Role_Archer then
            ax = 390
            ay = 585
            hx = 280
            hy = 585
            dx = 390
            dy = 535
            weaponX = 50
            weaponY = 570
            armorX = 145
            armorY = 570
            skX = 85
            skY = 450
        elseif role == Role_Master then
            ax = 270
            ay = 320
            hx = 410
            hy = 320
            dx = 270
            dy = 275
            weaponX = 500
            weaponY = 315
            armorX = 590
            armorY = 315
            skX = 350
            skY = 188
        end
        
        --- 属性数值
        local txtHp = GameNumbers:new(vNumberScore)
        txtHp:addLayer(_layerRole)
        txtHp:setPosition(gdccp(hx, hy))
        
        local txtAtk = GameNumbers:new(vNumberScore)
        txtAtk:addLayer(_layerRole)
        txtAtk:setPosition(gdccp(ax, ay))
        
        local txtDef = GameNumbers:new(vNumberScore)
        txtDef:addLayer(_layerRole)
        txtDef:setPosition(gdccp(dx, dy))
        
        _tableRole[role] = {lhp=txtHp, latk=txtAtk, ldef = txtDef}
        
        
        -- 显示装备
        --武器
        local items = CCSprite:createWithSpriteFrameName(_rinfo.Mweapon)
        items:setPosition(gdccp(weaponX, weaponY))
        --色彩
        if GetItems(_rinfo.weapon) > 0 then
        else
            items:setColor(ccc3(100,100,100))
        end
        _layerRole:addChild(items)
        --防具
        items = CCSprite:createWithSpriteFrameName(_rinfo.Marmor)
        items:setPosition(gdccp(armorX, armorY))
        --色彩
        if GetItems(_rinfo.armor) > 0 then
        else
            items:setColor(ccc3(100,100,100))
        end
        _layerRole:addChild(items)
        
        
        --- 技能
        
        -- 技能
        local sktable = _rinfo[PSkill]
        for k, vskID in pairs(sktable) do
            local skicon = SkillItemClass:new(vskID)
            skicon:addToLayer(_layerRole, _menu)
            
            skicon:setPosition(skX + (k-1)*103, skY)
            _tableSkillIcon[skicon.id] = skicon
        end
    end
    
    createRolePanel(Role_Soldier)
    createRolePanel(Role_Archer)
    createRolePanel(Role_Master)
    
    _updateProperty()
    
    return layer
end






--------------------------------
-- Click And Move Test
--------------------------------
function Create_Role_Scene(stage)
    local scene = CCScene:create()
    layer = CCLayer:create()

    initWithLayer(stage)

    scene:addChild(layer)
    scene:addChild(CreateBackMenuItem())

    return scene, UI_Role
end










----------------------- 类
--SkillItemClass = {}
----这句是重定义元表的索引，必须要有，
--SkillItemClass.__index = SkillItemClass
----模拟构造体，一般名称为new()
--function SkillItemClass:new(vskID, l, _layerRole, _batchNode, _batchNodeUnLock, _mainMenu)
--    local self = {}   
--    setmetatable(self, SkillItemClass)   --必须要有
--    
--    self.id = GetSkilllvID(vskID, l)
--    self._vskID = vskID
--    self._lv = l
--    
--    self._layerRole = _layerRole 
--    self._batchNode = _batchNode
--    self._batchNodeUnLock = _batchNodeUnLock
--    self._mainMenu = _mainMenu
--    
--    self.priceBg = nil
--    self.lbprice = nil
--    self._menuItem = nil
--    self._x, self._y = 0,0
--    
--    self._status = Status_Unlock
--    local _mysklls = GetSkill(self._vskID)
--    local _isend = false
--    if _mysklls ~= nil and _mysklls >= l then
--        self._status = Status_Normal
--        _isend = true
--        
--    else
--        -- 如果上一级没有解锁,则显示不可解锁
--        if l - _mysklls >= 2 then
--            self._status = Status_Lock
--            _isend = true
--        else
--            --显示价格
--            self.lbprice = CCLabelTTF:create(SkillTable_Infos[self._vskID][PLevel][self._lv][PCount], "Arial", FontSize-6)
--            --价格背景
--            self.priceBg = CCSprite:createWithSpriteFrameName("levelBg.png")
--            
--            self._layerRole:addChild(self.lbprice,3)
--        end
--    end
--    
--    --根据不同状态获得不同node
--    local bnode = nil
--    
--    local levelImg = "level_0%d.png"
--    local skillImg = "skill_0%d.png"
--    if self._status == Status_Lock then
--        levelImg = "levelUn_0%d.png"
--        skillImg = "skillUn_0%d.png"
--    else
--    end
--    
--    if self._status == Status_Unlock then
--        --解锁按钮
--        --self._menuItem = CCMenuItemLabel:create(CCLabelTTF:create("", "Arial", FontSize))
--        --self._menuItem:setContentSize(CCSizeMake(80,  80))
--        --self._menuItem:registerScriptTapHandler(_menuCallback)
--        --_mainMenu:addChild(self._menuItem, 0, self.id)
--    end
--    
--    --图标
--    local _spw = 70
--    local _sph = 71
--    local skindex = SkillTable_Infos[vskID][PModel]
--    
--    btnSpriteN =  CCSprite:createWithSpriteFrameName(string.format(skillImg, skindex+1))
--    btnSpriteS =  CCSprite:createWithSpriteFrameName(string.format(skillImg, skindex+1))
--    btnSpriteS:setScale(1.2)
--    btnSpriteS:setContentSize(CCSizeMake(_spw*1.2, _sph*1.2))
--    self.sp_skill = CCMenuItemSprite:create(btnSpriteN, btnSpriteS)
--    self.sp_skill:registerScriptTapHandler(_menuCallback)
--    _mainMenu:addChild(self.sp_skill, 0, self.id)
--    
--    --等级
--    _spw = 28
--    _sph = 14
--    self.sp_level = CCSprite:createWithSpriteFrameName(string.format(levelImg,self._lv))
--    self._batchNode:addChild(self.sp_level,1)
--    
--    -- 已经解锁的背景
--    self.sp_unlockbg = nil
--    if self._status == Status_Normal then
--        _spw = 94
--        _sph = 95
--        self.sp_unlockbg = CCSprite:createWithSpriteFrameName("SkillBtnBg_01.png")
--        self._batchNodeUnLock:addChild(self.sp_unlockbg)
--        
--        self.sp_skill:setEnabled(false)
--    end
--    
--    if self.priceBg ~= nil then
--        self._batchNode:addChild(self.priceBg,1)
--    end
--    
--    return self  
--end
--function SkillItemClass:getPosition()
--end
--function SkillItemClass:setPosition(x,y)
--    if self.priceBg then
--        self.priceBg:setPosition(gdccp(x,y - 30))
--    end
--    if self.lbprice then
--        self.lbprice:setPosition(x+DWinSizeWidth/2, y+DWinSizeHeight/2 - 30)
--    end
--    
--    if self.sp_level then
--        self.sp_level:setPosition(gdccp(x+ 15,y + 30))
--    end
--    if self.sp_skill then
--        self.sp_skill:setPosition(gdccp(x,y))
--    end
--    
--    if self._menuItem then
--        self._menuItem:setPosition(gdccp(x,y))
--    end
--    
--    if self.sp_unlockbg then
--        self.sp_unlockbg:setPosition(gdccp(x,y))
--    end
--    
--    self._x, self._y = x,y
--end
--
---- 更新状态,更新图标显示
--function SkillItemClass:changeStatus(st)
--    
--    if self._status == Status_Unlock then
--        --移除价格相关
--        self._batchNode:removeChild(self.priceBg, true)
--        self._layerRole:removeChild(self.lbprice, true)
--        --显示背景
--        _spw = 94
--        _sph = 95
--        self.sp_unlockbg = CCSprite:createWithSpriteFrameName("SkillBtnBg_01.png")
--        self._batchNodeUnLock:addChild(self.sp_unlockbg)
--        
--        self.sp_skill:setEnabled(false)
--        self._menuItem = nil
--        self.priceBg = nil
--        self.lbprice = nil
--    elseif self._status == Status_Lock then
--        --移队灰色图标
--        self._batchNode:removeChild(self.sp_level, true)
--        
--        self.sp_skill:setEnabled(false)
--        self.sp_skill = nil
--        self.sp_level = nil
--    end
--    
--    if st == Status_Unlock then
--        --显示亮图标
--        local _spw = 70
--        local _sph = 71
--        local skindex = SkillTable_Infos[self._vskID][PModel]
--        
--        btnSpriteN = CCSprite:createWithSpriteFrameName(string.format("skill_0%d.png",skindex+1))
--        btnSpriteS = CCSprite:createWithSpriteFrameName(string.format("skill_0%d.png",skindex+1))
--        btnSpriteS:setScale(1.2)
--        btnSpriteS:setContentSize(CCSizeMake(_spw*1.2, _sph*1.2))
--        self.sp_skill = CCMenuItemSprite:create(btnSpriteN, btnSpriteS)
--        self.sp_skill:registerScriptTapHandler(_menuCallback)
--        self._mainMenu:addChild(self.sp_skill, 0, self.id)
--        
--        --等级
--        _spw = 28
--        _sph = 14
--        self.sp_level = CCSprite:createWithSpriteFrameName(string.format("level_0%d.png", self._lv))
--        self._batchNode:addChild(self.sp_level,1)
--        --解锁按钮
--        self._menuItem = CCMenuItemLabel:create(CCLabelTTF:create("", "Arial", 24))
--        self._menuItem:setContentSize(CCSizeMake(80,  80))
--        self._menuItem:registerScriptTapHandler(_menuCallback)
--        self._mainMenu:addChild(self._menuItem, 0, self.id)
--        --价格显示
--        self.lbprice = CCLabelTTF:create(SkillTable_Infos[self._vskID][PLevel][self._lv][PCount], "Arial", 18)
--        self._layerRole:addChild(self.lbprice,3)
--        
--        --价格背景
--        self.priceBg = CCSprite:createWithSpriteFrameName("levelBg.png")
--        self._batchNode:addChild(self.priceBg)
--    end
--    
--    self:setPosition(self._x, self._y)
--    self._status = st
--end






--local function initWithLayer(stage)
--    local _tableRole = {}
--    -------- ui
--    -- 背景
--    local _bgSpr = nil
--    _bgSpr = CCSprite:createWithSpriteFrameName(s_Space_bg)
--    _bgSpr:setPosition(DWinSizeWidth/2, DWinSizeHeight/2)
--    layer:addChild(_bgSpr)
--    _bgSpr = CCSprite:createWithSpriteFrameName(s_Space_bgHead)
--    _bgSpr:setPosition(DWinSizeWidth/2, 960-32)
--    layer:addChild(_bgSpr, 9)
--    
--    -- 魂力
--    local _gui_hl = CCSprite:createWithSpriteFrameName("GUI_HL.png")
--    _gui_hl:setPosition(gdccp(200, 70))
--    _gui_hl:setAnchorPoint(ccp(1, 0.5))
--    layer:addChild(_gui_hl)
--    
--    local _lblSoul = GameNumbers:new(vNumberScore, NumberAlginment_Left)
--    _lblSoul:addLayer(layer)
--    _lblSoul:setNumber(GetSoulPower())
--    _lblSoul:setPosition(gdccp(220, 65))
--    
--    
--    
--    local _tableSkillIcon = {}
--    
--    --- 更新角色数值显示
--    local function _updateProperty()
--        for k,rid in pairs({Role_Soldier, Role_Archer, Role_Master}) do
--            local proobj = GetRoleProperty(rid)
--            _tableRole[rid].lhp:setString(string.format("生命:%i",proobj.hp))
--            _tableRole[rid].latk:setString(string.format("伤害:%i",proobj.atk))
--            _tableRole[rid].ldef:setString(string.format("护甲:%i",proobj.def))
--        end
--    end
--    
--    -- 按钮回调函数
--    _menuCallback = function (tag)
--        Play_Effect(sme_Click)
--        -- 技能按钮tag  技能*100+等级
--        local lv = tag%IndexSkillTag
--        local sk = (tag-lv)/IndexSkillTag
--        
--        
--        --状态可解锁
--        if _tableSkillIcon[tag]._status ~= Status_Unlock then
--            return
--        end
--        
--        ---- 直接升级
--        -- 是否有足够的魂力值
--        local _jiage = SkillTable_Infos[lv][PLevel][lv][PCount]
--        if GetSoulPower() >= _jiage then
--            -- 升级
--            UpSkill(sk, lv)
--            -- 更新按钮
--            _tableSkillIcon[tag]:changeStatus(Status_Normal)
--            -- 更新显示下级的升级按钮
--            if lv < 3 then
--                _tableSkillIcon[tag+1]:changeStatus(Status_Unlock)
--            end
--            --减少魂力值
--            AddSoulPower(-_jiage)
--            _lblSoul:setNumber(GetSoulPower())
--            --Play_Effect(sme_BuyEnd)
--            
--            --音效
--            Play_Effect(sme_Achieve)
--            
--            _updateProperty()
--        else
--            -- 魂力值不足
--            CCDialogClose("魂力值不足!")
--            Play_Effect(sme_ClickError)
--        end
--    end
--    
--    
--    
--    
--    
--    
--    ---翻页容器
--    local container = GameContainerPage:new(DWinSizeWidth, 0)
--    container:addToLayer(layer)
--    
--    local ipage = -1
--    
--    
--    -- 不同的职业用不同的页面切换
--    local btnSpriteN = nil
--    local btnSpriteS = nil
--    local btnItem = nil
--    local _batchNode = nil
--    local _batchNodeUnLock = nil
--    local _mainMenu = nil
--    local _layerRole = nil
--    
--    
--    -- 显示模型
--    require "lua/ui_fight"
--    -- 战场layer
--    local _tableRoles = {}
--    
--    -- 创建职业面板
--    local function createRolePanel(role)
--        _layerRole = CCLayer:create()
--        container:addChild(_layerRole)
--        
--        _mainMenu = CCMenu:create()
--        _layerRole:addChild(_mainMenu,1)
--        _batchNode = CCSpriteBatchNode:create(s_MainUI2)
--        _layerRole:addChild(_batchNode,3)
--        _batchNode:setPosition(DWinSizeWidth/2, DWinSizeHeight/2)
--        
--        _batchNodeUnLock = CCSpriteBatchNode:create(s_MainUI2)
--        _layerRole:addChild(_batchNodeUnLock,0)
--        _batchNodeUnLock:setPosition(DWinSizeWidth/2, DWinSizeHeight/2)
--        
--        -- 职业
--        local _rinfo = Datas_Role[role]
--        --print(_rinfo, _rinfo[PSkill])
--        -- 背景
--        local bpx, bpy = DWinSizeWidth/2,0
--        -- 升级树
--        _bgSpr = CCSprite:createWithSpriteFrameName(s_Profess_LvbgSk)
--        _bgSpr:setPosition(bpx, 650)
--        _layerRole:addChild(_bgSpr)
--        -- 角色背景
--        _bgSpr = CCSprite:createWithSpriteFrameName(s_Profess_lvbgPy)
--        _bgSpr:setPosition(bpx, 400)
--        _layerRole:addChild(_bgSpr)
--        -- 信息面板
--        _bgSpr = CCSprite:createWithSpriteFrameName(s_infoBarR)
--        _bgSpr:setPosition(bpx, 200)
--        _layerRole:addChild(_bgSpr)
--        
--        -- 显示装备
--        local _spw = 70
--        local _sph = 71
--        --武器
--        local items = CCSprite:createWithSpriteFrameName(_rinfo.Mweapon)
--        items:setPosition(-200, 0 - 50)
--        --色彩
--        if GetItems(_rinfo.weapon) > 0 then
--        else
--            items:setColor(ccc3(100,100,100))
--        end
--        _batchNode:addChild(items)
--        --防具
--        items = CCSprite:createWithSpriteFrameName(_rinfo.Marmor)
--        items:setPosition(-200, -90 - 50)
--        --色彩
--        if GetItems(_rinfo.armor) > 0 then
--        else
--            items:setColor(ccc3(100,100,100))
--        end
--        _batchNode:addChild(items)
--        
--        -- 属性面板
--        local lbpro_hp = CCLabelTTF:create("生命:0", "Arial", FontSize)
--        lbpro_hp:setColor(ccc3(12, 222, 55))--颜色
--        lbpro_hp:setAnchorPoint(ccp(0, 0.5))
--        lbpro_hp:setPosition(300, 220)
--        _layerRole:addChild(lbpro_hp,2)
--        
--        local lbpro_atk = CCLabelTTF:create("伤害:0", "Arial", FontSize)
--        lbpro_atk:setColor(ccc3(255, 88, 55))--颜色
--        lbpro_atk:setPosition(130, 220)
--        lbpro_atk:setAnchorPoint(ccp(0, 0.5))
--        _layerRole:addChild(lbpro_atk,2)
--        
--        local lbpro_def = CCLabelTTF:create("护甲:0", "Arial", FontSize)
--        lbpro_def:setColor(ccc3(55, 152, 255))--颜色
--        lbpro_def:setPosition(130, 170)
--        lbpro_def:setAnchorPoint(ccp(0, 0.5))
--        _layerRole:addChild(lbpro_def,2)
--        _tableRole[role] = {lhp=lbpro_hp, latk=lbpro_atk, ldef = lbpro_def}
--        
--        ----头衔
--        local lbtitles = CCLabelTTF:create(GetMyTitles() == "" and "无头衔" or GetMyTitles(), "Arial", FontSize + 8)
--        lbtitles:setColor(ccc3(255, 150, 55))--颜色
--        lbtitles:setPosition(500, 390)
--        lbtitles:setAnchorPoint(ccp(0.5, 0.5))
--        _layerRole:addChild(lbtitles,2)
--        
--        -- 技能
--        local sktable = _rinfo[PSkill]
--        for k, vskID in pairs(sktable) do
--            local sinfo = SkillTable_Infos[vskID]
--            --等级PLevel
--            for l, _Vskill in pairs(sinfo[PLevel]) do
--                --不同技能的坐标
--                local sklpx, sklpy = 0,0
--                if k == 1 then
--                    sklpx = -150
--                    sklpy = 100
--                elseif k == 2 then
--                    sklpx = 0
--                    sklpy = 70
--                elseif k == 3 then
--                    sklpx = 155
--                    sklpy = 135
--                end
--                sklpy = sklpy + (l-1)*120
--                sklpx = sklpx
--                
--                --- 按钮,判断是否已经提升过,显示不同的背景按钮
--                local skicon = SkillItemClass:new(vskID, l, _layerRole, _batchNode, _batchNodeUnLock, _mainMenu)
--                skicon:setPosition(sklpx, sklpy)
--                _tableSkillIcon[skicon.id] = skicon
--            end
--        end
--        
--        
--        --- 加载模型
--        --local model = Player:new(role, role, false)
--        --model:setPosition(gdccp(DWinSizeWidth /2, 330))
--        --model._iTeam = 1
--        --model.model:setScale(Datas_Role[role][PScale])
--        --table.insert(_tableRoles, model)
--        
--        --_layerRole:addChild(model._layerUi)
--        --_layerRole:addChild(model._layerUItop,3)
--        
--        
--        local batchNode = CCSpriteBatchNode:create("fmodel/role.png")
--        _layerRole:addChild(batchNode,1)
--        
--        _SPyinYing = CCSprite:createWithSpriteFrameName("py_yingy.png")
--        _SPyinYing:setPosition(DWinSizeWidth /2,330)
--        _layerRole:addChild(_SPyinYing)
--        
--        local anim = CCArmature:create(Datas_Role[role][PModel], Datas_Role[role][PModel], batchNode)
--        anim:getDisplay():setPosition(gdccp(DWinSizeWidth /2, 330))
--        anim:getDisplay():setScale(Datas_Role[role][PScale])
--        table.insert(_tableRoles, anim)
--        
--        anim:getAnimation():playTo(Action_Stand)
--    end
--    
--    -- 战士
--    createRolePanel(Role_Soldier)
--    createRolePanel(Role_Archer)
--    createRolePanel(Role_Master)
--    _updateProperty()
--    
--    
--    local function update(dt)
--        table.foreach(_tableRoles, function(k, anim)
--            anim:update(dt)
--        end)
--    end
--    ---暂停游戏
--    local _joinGame = false
--    local _gameRun = false
--    local _baseLayer_entry = nil
--    local function _onGameRun()
--        if not _gameRun then
--            _baseLayer_entry = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc(update,1.0/60.0,false)
--            _gameRun = true
--        else
--            if _baseLayer_entry ~= nil then
--                CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry(_baseLayer_entry)
--            end
--            _baseLayer_entry = nil
--            _gameRun = false
--        end
--    end
--    
--    local function SpriteEase_onEnterOrExit(tag,tag2)
--        if not _joinGame then
--            _joinGame = true
--            _gameRun = false
--        else
--            _joinGame = false
--            _gameRun = true
--        end
--        _onGameRun()
--    end
--    -- 注册进入/退出事件
--    layer:registerScriptHandler(SpriteEase_onEnterOrExit)
--
--    return layer
--end

